<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>用户授权</title>
		<script language="javascript" type="text/javascript">
		//角色授权
		function grantUser(){
			var selected = document.getElementById("roleTemp2");
			var userIdS = document.getElementsByTagName("input");
			var roleNameS1 = "";
			var userIdSTemp="";
			if(selected != ""){
				for(var i=0;i<selected.length;i++){
					roleNameS1 += selected[i].value+",";//使用“,”拼接，在userAction中进行解析
				}
				for(var j=0;j<userIdS.length;j++){
					var obj = userIdS[j];
					if(obj.type=='hidden'){
						userIdSTemp += userIdS[j].value+",";
					}
				}
				var form = document.getElementById("regform");
				form.action = "system/userAction!grantUser.do?roleNameS=" + roleNameS1+"&userIds="+
				userIdSTemp;
				form.submit();
				} else {
					window.alert("请选择角色！");
				}
			}
	
		//角色授权或删除
		function chooseRole(n1, n2) {
			while (n1.selectedIndex != -1) {
				var indx = n1.selectedIndex;
				var t = n1.options[indx].text;
				n2.options.add(new Option(t));
				n1.remove(indx);
			}
		}
			 
		</script>
	</head>
	<body>

		<div class="main-con">
			<!--//导航位置层-->
			<div class="main-bar">
				<span class="bar-position">当前位置：<a href="#">首页</a> 》 系统管理 》
					用户管理 》用户授权</span>
			</div>
			<div class="data-area">
				<s:form method="post" id="regform" name="formGrant">
					<div class="waybill-title">
						<div align="center">
							<span>请设置用户的权限信息</span>
						</div>
					</div>
					<table width="100%" border="0" cellspacing="0" cellpadding="0"
						class="datalist">
						<tr>
							<td colspan="3" class="tdleft f1">
								<span class="fontCo">用户名：</span>
								<s:iterator value="userList" status="user" var="user">
									<input name="userIdS" type="hidden"
										value="<s:property value='userId'/>" id="userIdS" />
									<s:property value='userName' />
									<s:if test="#user.count >= 2">,</s:if>
								</s:iterator>
							</td>
						</tr>
						<tr>
							<th width="35%">
								所有权限
							</th>
							<td rowspan="2">
								<img src="../images/warrant.png" width="45" height="40"
									border="0"
									onclick="chooseRole(document.formGrant.roleTemp1,document.formGrant.roleTemp2);" />
								<br />
								<br />
								<img src="../images/delete.png" width="45" height="40"
									border="0"
									onclick="chooseRole(document.formGrant.roleTemp2,document.formGrant.roleTemp1);" />
							</td>
							<th width="35%">
								已有权限
							</th>
						</tr>
						<tr>
							<td>
								<!-- 所有权限 -->
								<select id="roleTemp1" name="roleTemp1"
									style="width: 300px; height: 200px;" class="commtxtarea"
									size="13" multiple="multiple">
									<s:iterator value="roleList" status="role" var="role">
										<option id="roleOption" value="<s:property value='roleId' />">
											<s:property value="roleName" escape="false" />
										</option>
									</s:iterator>
								</select>
							</td>
							<td>
								<!-- 已有权限 -->
								<select id="roleTemp2" name="roleTemp2"
									style="width: 300px; height: 200px;" class="commtxtarea"
									size="13" multiple="multiple">
									<s:iterator value="user.userRoles" status="userR" var="userR">
										<option id="roleOption" value="<s:property value='roleName' />">
											<s:property value="roleName" escape="false" />
										</option>
									</s:iterator>
								</select>
							</td>
						</tr>
						<tr style="height: 40px;">
							<td colspan="3">
								<div>
									<input type="button" name="button" id="button" value="确 定"
										class="btn-Yes" onclick="grantUser()" />
									<input type="button" name="button2" id="button2" value="返 回"
										class="btn-No" onclick="history.go(-1);" />
								</div>
							</td>
						</tr>
					</table>
				</s:form>
			</div>
		</div>
	</body>
</html>
